package com.ck.client.controller;

import com.ck.client.service.MonitService;
import com.ck.common.model.OperationResult;
import com.ck.core.annotation.ClientPermissionRequired;
import com.ck.core.constant.BusinessConstant;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * @description: 监播上传
 * @author: zhanglei
 * @date: 2019/4/22 18:39
 */
@Controller
@ClientPermissionRequired
public class CkMonitController {

    private static Logger logger = LoggerFactory.getLogger(CkClientController.class);
    @Autowired
    private MonitService monitService;


    /**
     * 终端上传监播数据
     */
    @ResponseBody
    @PostMapping(value = "/reportShows")
    public Object reportShows(HttpServletRequest request, String jsonData){
        String deviceCode = (String) request.getAttribute(BusinessConstant.CHAR_DEVICE_CODE);
        if(StringUtils.isBlank(jsonData)){
            return OperationResult.newValidateFailOperationResult("jsonData为必传参数");
        }
        try{
            monitService.reportShows(deviceCode,jsonData);
            return OperationResult.newSuccessOperationResult();
        } catch (Exception e) {
            logger.error("ClientController report 终端上报监播信息异常：【" + deviceCode + "】"+e.getMessage(),e);
            return OperationResult.newSystemErrorOperationResult();
        }
    }
}
